package com.edu.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.entity.Course;

import com.edu.entity.chapter.ChapterVo;
import com.edu.entity.course.CourseFontVo;
import com.edu.entity.course.CourseWebVo;
import com.edu.service.ChapterService;
import com.edu.service.CourseService;
import com.edu.service.TeacherService;
import com.edu.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @author 麦翔盛
 * @description: 课程前台查询控制类
 * @date 2021/11/14 23:14
 */
@CrossOrigin
@RestController
@RequestMapping("/edu/font/course")
public class CourseFontController {
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private CourseService courseService;
    @Autowired
    private ChapterService chapterService;

    @PostMapping("/list/{page}/{limit}")
    public R getCourseList(@PathVariable long page,
                           @PathVariable long limit,
                           @RequestBody(required = false) CourseFontVo courseFontVo){
        Page<Course> coursePage = new Page<>(page, limit);
        HashMap<String,Object> map = teacherService.getCoursePage(coursePage,courseFontVo);
        return R.success().data(map);
    }

    @GetMapping("/getFontCourseInfo/{courseId}")
    public R getFontCourseInfo(@PathVariable String courseId){
        //获取课程信息
        CourseWebVo courseWebVo = courseService.getBaseCourseInfo(courseId);

        //获取章节信息
        List<ChapterVo> chapterVideoList = chapterService.getChapterVideoVoByCourseId(courseId);

        return R.success().data("courseWebInfo",courseWebVo)
                .data("chapterVideoList",chapterVideoList);
    }
}
